// JavaScript Document 
    //上传图片
    function wxChooseImage() {
        wx.chooseImage({
            success: function (res) {
                var i = 0, length = res.localIds.length;
                
                function upload() {
                    //判断是否已经上传了足够的图片
                    var len = $(".file-item").length;
                    if (len >= 4) {
                        alert("上传图片数量已达上限");
                        return;
                    }
                    //图片上传到微信服务器
                    $("#loadingToast").css("display","block");
                    wx.uploadImage({
                        localId: res.localIds[i],
                        success: function (result) {
//                            alert(JSON.stringify(result));
                            var imgList = '<li class="weui-uploader__file file-item" style="position: relative;">' +
                                '<img src="' + res.localIds[i] + '" style="width:79px;height:79px;" />' +
                                '<span class="del" onclick="delImg(this)">x</span>' +
                                '<input type="hidden"  name="filename" value="" />' +
                                '</li>';
                            var imgtoadd=$("#uploaderFiles").append(imgList).find("li").last();
                            $("#already_upload").html($(".file-item").length);
                            //转服务器下载图片，下载完成后交图片文件名取回，放到数组里 （by liheng)
                            $.ajax({
                                type: 'POST',
                                url: '/myapps/saveimg.php',
                                // data to be added to query string:
                                data: { serviceid: result.serverId },
                                // type of data we are expecting in return:
                                dataType: 'json',
                                timeout: 2000,
                                context: imgtoadd,
                                success: function(data){
                                    // Supposing this JSON payload was received:
                                    //   {stat:ok,"msg":"1223.jpg"}    
                                    if(data.stat=='error') {
                                        alert('图片保存失败:'+ data.msg);return;
                                    }else 
                                    imgtoadd.find("input").val(data.msg);
                                    $("#loadingToast").css("display","none");
                                    
                                },
                                error: function(xhr, type,error){
                                    alert('图片保存失败:'+ error);
                                    $("#loadingToast").css("display","none");
                                }
                            }) 



                            i++;
                            if (i < length) {
                                upload();
                            }
                        },
                        fail: function (res) {
                            alert(JSON.stringify(res));
                            $("#loadingToast").css("display","none");
                        }
                    });
                }

                upload();
                 
            }
        });
    }
    wx.error(function (res) {
        alert("调用微信jsapi返回的状态:" + res.errMsg);
    });//删除图片
    function delImg(dom) {
        $(dom).parent().remove();
        $("#already_upload").html($(".file-item").length);
    }

    function getDatestr(){   
        var date = new Date(); //创建时间对象  
    
        var year = date.getFullYear(); //获取年   
    
        var month = date.getMonth()+1;//获取月
    
        var day = date.getDate(); //获取当日  
    
        var time = year+"-"+month+"-"+day; //组合时间  
    
        return time;  
    
    } 
     
     
    
        //读取cookies 
    function getCookie(name) {
        var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    
        if (arr = document.cookie.match(reg)) return unescape(arr[2]);
        else return null;
    }

  